<?php

namespace app\health\controller;

use app\health\model\HealthPayment;

class Payment extends ApiBase
{
	protected $noNeedLogin = ['status'];

	/**
	 * 查询支付订单状态
	 * @return void
	 * @throws \think\db\exception\DataNotFoundException
	 * @throws \think\db\exception\ModelNotFoundException
	 * @throws \think\exception\DbException
	 */
	public function status(): void
	{
		$paymentId = $this->request->param('payment_id');
		$payment   = HealthPayment::where('id', $paymentId)->find();
		$data      = [
			'type'       => $payment['type'],
			'pay_status' => $payment['pay_status']
		];
		if ((int)$payment['pay_status'] === 1 && (int)$payment['type'] === 1) {
			$this->auth->direct($payment['user_id']);
			$data['userinfo'] = $this->auth->getUserinfo();
		}
		$this->success('success', $data);
	}
}